import { cloneDeep } from "lodash-es"
import Basic from "@/global"

export interface BuffDataSet {
  name: string
  effects: EffectData[]
  description: string
  pro?: (pro: any) => any
}

export interface BuffData {
  buff_id: number
  id:string
  custom_num: number
  caster_id: string
  host_id: string
}


export class Buff {
  aura?:Aura
  name:string
  dur:number
  pro:Function
  custom_num!:number
  cdTiming:string
  permanent:boolean
  effects:Record<number,Effect>
  constructor(public id:string,public buff_id:number,public caster:Fightcard,public host:Fightcard, custom_num:number|undefined,public battle:Battle) {
      let buff = cloneDeep(Basic.buff[buff_id])
      this.id = id
      this.buff_id = buff_id
      this.battle = battle
      this.name = buff.name || ""
      this.permanent = buff.permanent
      this.dur = buff.dur
      this.cdTiming = buff.cdTiming
      this.pro = buff.pro
      this.effects = {}
      this.caster = caster
      this.host = host
      this.custom_num = custom_num ?? buff.custom_num ?? 0
      this.conditionTri = buff.conditionTri || {}

      // 设置effect
      for (let i in buff.effects || {}) {
          let eff = buff.effects[i]
          let effect = {} as Effect
          effect.id = eff.id
          effect.hide = eff.hide
          effect.timing = eff.timing
          effect.effect = cloneDeep(Basic.effect[eff.id])
          this.effects[+i] = effect
      }
  }
}